import * as types from '../mutation-types'
import { mainRouter } from '@/router/index';
import loginService from 'service/loginService.js'

const state = {
    menuList: []
}

const getters = {
    menuList: () => state.menuList

}
const getMenuDataL = [{
        "menuPreId": null,
        "children": [],
        "seqNum": 1,
        "menuId": "1",
        "menuName": "首页",
        "menuType": "4",
        "url": "home"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 2,
        "menuId": "2",
        "menuName": "语音客服",
        "menuType": "4",
        "url": "callConfirm"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 3,
        "menuId": "3",
        "menuName": "公告管理",
        "menuType": "4",
        "url": "announcementmanage"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 5,
        "menuId": "4",
        "menuName": "我的公告",
        "menuType": "4",
        "url": "ownannouncement"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 4,
        "menuId": "5",
        "menuName": "话术管理",
        "menuType": "4",
        "url": "wordoperation"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 6,
        "menuId": "6",
        "menuName": "我的工单",
        "menuType": "4",
        "url": "taskmine"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 7,
        "menuId": "7",
        "menuName": "待处理工单",
        "menuType": "4",
        "url": "taskuntreated"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 8,
        "menuId": "8",
        "menuName": "待分配工单",
        "menuType": "4",
        "url": "taskpending"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 9,
        "menuId": "9",
        "menuName": "工单管理",
        "menuType": "4",
        "url": "taskmanage"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 10,
        "menuId": "10",
        "menuName": "我的记录",
        "menuType": "4",
        "url": "record"
    }

]
const getMenuDataMa = [{
        "menuPreId": null,
        "children": [],
        "seqNum": 1,
        "menuId": "1",
        "menuName": "首页",
        "menuType": "4",
        "url": "home"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 2,
        "menuId": "2",
        "menuName": "语音客服",
        "menuType": "4",
        "url": "callConfirm"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 3,
        "menuId": "3",
        "menuName": "公告管理",
        "menuType": "4",
        "url": "announcementmanage"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 5,
        "menuId": "4",
        "menuName": "我的公告",
        "menuType": "4",
        "url": "ownannouncement"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 4,
        "menuId": "5",
        "menuName": "话术管理",
        "menuType": "4",
        "url": "wordoperation"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 6,
        "menuId": "6",
        "menuName": "我的工单",
        "menuType": "4",
        "url": "taskmine"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 7,
        "menuId": "7",
        "menuName": "待处理工单",
        "menuType": "4",
        "url": "taskuntreated"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 8,
        "menuId": "8",
        "menuName": "待分配工单",
        "menuType": "4",
        "url": "taskpending"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 9,
        "menuId": "9",
        "menuName": "工单管理",
        "menuType": "4",
        "url": "taskmanage"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 10,
        "menuId": "10",
        "menuName": "我的记录",
        "menuType": "4",
        "url": "record"
    }, {
        "menuPreId": null,
        "children": [],
        "seqNum": 11,
        "menuId": "11",
        "menuName": "标签管理",
        "menuType": "4",
        "url": "TagManagement"
    }, {
        "menuPreId": null,
        "children": [],
        "seqNum": 12,
        "menuId": "12",
        "menuName": "添加标签",
        "menuType": "4",
        "url": "AddTag"
    }, {
        "menuPreId": null,
        "children": [],
        "seqNum": 13,
        "menuId": "13",
        "menuName": "标签列表",
        "menuType": "4",
        "url": "ListTag"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 14,
        "menuId": "14",
        "menuName": "知识库",
        "menuType": "4",
        "url": "repository"
    }
]
const getMenuDataM = [{
        "menuPreId": null,
        "children": [],
        "seqNum": 1,
        "menuId": "1",
        "menuName": "首页",
        "menuType": "4",
        "url": "home"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 2,
        "menuId": "2",
        "menuName": "语音客服",
        "menuType": "4",
        "url": "callConfirm"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 5,
        "menuId": "4",
        "menuName": "我的公告",
        "menuType": "4",
        "url": "ownannouncement"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 6,
        "menuId": "6",
        "menuName": "我的工单",
        "menuType": "4",
        "url": "taskmine"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 7,
        "menuId": "7",
        "menuName": "待处理工单",
        "menuType": "4",
        "url": "taskuntreated"
    },
    {
        "menuPreId": null,
        "children": [],
        "seqNum": 10,
        "menuId": "10",
        "menuName": "我的记录",
        "menuType": "4",
        "url": "record"
    }
]

const getMenuDataLess = [{
    "menuPreId": null,
    "children": [],
    "seqNum": 1,
    "menuId": "1",
    "menuName": "首页",
    "menuType": "4",
    "url": "home"
}]

const actions = {
    async updateMenulist({ commit }, data) {
        let getMenuData;
        let menutree = await loginService.getMenuList(data)
        if (menutree.length) {
            getMenuData = menutree[0].children;
            let menuList = [];
            mainRouter.children.forEach((item, index) => {
                getMenuData.forEach((get_item, get_index) => {
                    if (item.title === get_item.menuName) {
                        menuList.push(item);
                    }
                })
            });
            commit(types.MENU_LIST, menuList)
        }
    },
    updateRouter({ commit }) {

    }
}
const mutations = {
    // [types.MENU_LIST](state, menuList) {
    //     state.menuList = menuList
    // }
    [types.MENU_LIST](state, menuList) {
        state.menuList = menuList
    },
    updateRouter(state, isKeepLive) {
        let mainData = mainRouter.children
        mainData.forEach((val, index) => {
            // console.log(val)
            if (val.path == '/voicecall') {
                val.meta.keepAlive = isKeepLive
                console.log(val.meta.keepAlive)
            }
        })
        return false
    }
}
export default {
    state,
    getters,
    actions,
    mutations
}